#include <algorithm>
#include <cstdio>
#include <cstring>

const int N = 20005;
int n, t, w, h, hash[N];

struct Node {
  int val, tag;
} tr[N << 2];

struct Event {
  Event() : x(), y(), l() {}
  Event(int x, int y, int l) : x(x), y(y), l(l) {}
  int x, y, l;
  inline bool operator<(const Event &rhs) const {
    return x == rhs.x ? l > rhs.l : x < rhs.x;
  }
} eve[N];

inline void pushup(int x) { tr[x].val = std::max(tr[x << 1].val, tr[x << 1 | 1].val); }

inline void pushdown(int x) {
  static int ls, rs;
  if (tr[x].tag) {
    ls = x << 1, rs = x << 1 | 1;
    tr[ls].tag += tr[x].tag;
    tr[rs].tag += tr[x].tag;
    tr[ls].val += tr[x].tag, tr[rs].val += tr[x].tag;
    tr[x].tag = 0;
  }
}

void modify(int x, int l, int r, int L, int R, int v) {
  if (L <= l && r <= R) return tr[x].tag += v, tr[x].val += v, void();
  int mid = (l + r) >> 1;
  pushdown(x);
  if (L <= mid) modify(x << 1, l, mid, L, R, v);
  if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R, v);
  pushup(x);
}

int query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return tr[x].val;
  int mid = (l + r) >> 1, res = 0;
  pushdown(x);
  if (L <= mid) res = std::max(res, query(x << 1, l, mid, L, R));
  if (mid < R) res = std::max(res, query(x << 1 | 1, mid + 1, r, L, R));
  return res;
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("ScanLine.in", "r", stdin);
  freopen("ScanLine.out", "w", stdout);
#endif
#endif

  scanf("%d", &t);
  while (t--) {
    memset(tr, 0, sizeof(tr));
    hash[0] = 0;
    scanf("%d%d%d", &n, &w, &h);
    for (int i = 1; i <= n; ++i) {
      scanf("%d%d%d", &eve[i].x, &eve[i].y, &eve[i].l);
      hash[++hash[0]] = eve[i].y;
      hash[++hash[0]] = eve[i].y + h - 1;
      eve[i + n] = Event(eve[i].x + w - 1, eve[i].y, -eve[i].l);
    }
    std::sort(eve + 1, eve + n * 2 + 1);
    std::sort(hash + 1, hash + hash[0] + 1);
    hash[0] = std::unique(hash + 1, hash + hash[0] + 1) - hash - 1;
    int ans = 0;
    for (int i = 1; i <= n << 1; ++i) {
      modify(1, 1, hash[0],
             std::lower_bound(hash + 1, hash + hash[0] + 1, eve[i].y) - hash,
             std::lower_bound(hash + 1, hash + hash[0] + 1, eve[i].y + h - 1) - hash,
             eve[i].l);
      ans = std::max(ans, tr[1].val);
    }
    printf("%d\n", ans);
  }
  return 0;
}